<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/30 0030
 * Time: 17:09
 */

namespace app\api\validate;


class IDCollection extends BaseValidate
{
//    ids=id1,id2,id3.....
    protected $rule = [
        'ids' => 'require|checkIDs'
    ];
    protected $message = [
        'ids' => 'ids参数必须是以逗号分隔的多个正整数'
    ];
//    自定义验证规则
    protected function checkIDs($value, $rule='', $data='', $field = ''){
        $values = explode(',',$value);
        if (empty($value)){
            return false;
        }
        foreach ($values as $id){
            if (!$this->isPositiveInteger($id)){
                return false;
            }
        }
        return true;
    }
}